/**
  *******************************************************************************************************
  * @file    fm33le0xxa_fl_divas.h
  * @author  FMSH Application Team
  * @brief   Head file of DIVAS FL Module
  *******************************************************************************************************
  * @attention
  * Copyright (c) 2022, SHANGHAI FUDAN MICROELECTRONICS GROUP CO., LTD.(FUDAN MICROELECTRONICS./ FUDAN MICRO.)    
  * All rights reserved.    
  *    
  * Processor:                   FM33LE0xxA    
  * http:                        http://www.fmdevelopers.com.cn/    
  *    
  * Redistribution and use in source and binary forms, with or without    
  * modification, are permitted provided that the following conditions are met    
  *    
  * 1. Redistributions of source code must retain the above copyright notice,    
  *    this list of conditions and the following disclaimer.    
  *    
  * 2. Redistributions in binary form must reproduce the above copyright notice,    
  *    this list of conditions and the following disclaimer in the documentation    
  *    and/or other materials provided with the distribution.    
  *    
  * 3. Neither the name of the copyright holder nor the names of its contributors    
  *    may be used to endorse or promote products derived from this software    
  *    without specific prior written permission.    
  *    
  * 4. To provide the most up-to-date information, the revision of our documents     
  *    on the World Wide Web will be the most Current. Your printed copy may be      
  *    an earlier revision. To verify you have the latest information avaliable,    
  *    refer to: http://www.fmdevelopers.com.cn/.    
  *    
  * THIS SOFTWARE IS PROVIDED BY FUDAN MICRO "AS IS" AND ANY EXPRESSED     
    ORIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES     
    OF MERCHANTABILITY NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE    
    ARE DISCLAIMED.IN NO EVENT SHALL FUDAN MICRO OR ITS CONTRIBUTORS BE LIABLE     
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL     
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS     
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER    
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,     
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY WAY OUT OF THE     
    USE OF THIS SOFTWARE, EVEN IF ADVISED OFTHE POSSIBILITY OF SUCH DAMAGE.    
  *******************************************************************************************************
  */


/* Define to prevent recursive inclusion---------------------------------------------------------------*/
#ifndef __FM33LE0XXA_FL_DIVAS_H
#define __FM33LE0XXA_FL_DIVAS_H

#ifdef __cplusplus
extern "C" {
#endif
/* Includes -------------------------------------------------------------------------------------------*/
#include "fm33le0xxa_fl_def.h"
/** @addtogroup FM33LE0XXA_FL_Driver
  * @{
  */

/** @defgroup DIVAS DIVAS
  * @brief DIVAS FL driver
  * @{
  */

/* Exported types -------------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_ES_INIT DIVAS Exported Init structures
  * @{
  */

/**
  * @}
  */
/* Exported constants ---------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_Exported_Constants DIVAS Exported Constants
  * @{
  */

#define    DIV_SR_DIVBYZERO_Pos                                   (1U)
#define    DIV_SR_DIVBYZERO_Msk                                   (0x1U << DIV_SR_DIVBYZERO_Pos)
#define    DIV_SR_DIVBYZERO                                       DIV_SR_DIVBYZERO_Msk

#define    DIV_SR_BUSY_Pos                                        (0U)
#define    DIV_SR_BUSY_Msk                                        (0x1U << DIV_SR_BUSY_Pos)
#define    DIV_SR_BUSY                                            DIV_SR_BUSY_Msk



#define    FL_DIVAS_SR_BUSY_TIMEOUT                               0xFFFU



/**
  * @}
  */
/* Exported functions ---------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_Exported_Functions DIVAS Exported Functions
  * @{
  */

/**
  * @brief    Write Dividend Register
  * @rmtoll   OPRD        FL_DIV_WriteDividend_S32
  * @param    DIVx DIV instance
  * @param    number
  * @retval   None
  */
__STATIC_INLINE void FL_DIV_WriteDividend_S32(DIV_Type *DIVx, uint32_t number)
{
    WRITE_REG(DIVx->END, (number << 0U));
}

/**
  * @brief    Read Dividend Register
  * @rmtoll   OPRD        FL_DIV_ReadDividend_S32
  * @param    DIVx DIV instance
  * @retval
  */
__STATIC_INLINE int32_t FL_DIV_ReadDividend_S32(DIV_Type *DIVx)
{
    return (int32_t)(READ_REG(DIVx->END));
}

/**
  * @brief    Write 16bit Signed Divisor
  * @rmtoll   DIVSOR        FL_DIV_WriteDivisor_S16
  * @param    DIVx DIV instance
  * @param    number
  * @retval   None
  */
__STATIC_INLINE void FL_DIV_WriteDivisor_S16(DIV_Type *DIVx, uint32_t number)
{
    MODIFY_REG(DIVx->SOR, (0xffffU << 0U), (number << 0U));
}

/**
  * @brief    Read 16bit Signed Divisor
  * @rmtoll   DIVSOR        FL_DIV_ReadDivisor_S16
  * @param    DIVx DIV instance
  * @retval
  */
__STATIC_INLINE int16_t FL_DIV_ReadDivisor_S16(DIV_Type *DIVx)
{
    return (int16_t)(READ_BIT(DIVx->SOR, (0xffffU << 0U)) >> 0U);
}

/**
  * @brief    Read 32bit Signed QUTO
  * @rmtoll   QUOT        FL_DIV_ReadQuotient_S32
  * @param    DIVx DIV instance
  * @retval
  */
__STATIC_INLINE int32_t FL_DIV_ReadQuotient_S32(DIV_Type *DIVx)
{
    return (int32_t)(READ_REG(DIVx->QUOT));
}

/**
  * @brief    Read 16bit Signed Reminder
  * @rmtoll   REMD        FL_DIV_ReadResidue_S16
  * @param    DIVx DIV instance
  * @retval
  */
__STATIC_INLINE int16_t FL_DIV_ReadResidue_S16(DIV_Type *DIVx)
{
    return (int16_t)(READ_BIT(DIVx->REMD, (0xffffU << 0U)) >> 0U);
}

/**
  * @brief    Get divided by 0 flag
  * @rmtoll   SR    DIVBYZERO    FL_DIV_IsActiveFlag_DividedZero
  * @param    DIVx DIV instance
  * @retval   State of bit (1 or 0).
  */
__STATIC_INLINE uint32_t FL_DIV_IsActiveFlag_DividedZero(DIV_Type *DIVx)
{
    return (uint32_t)(READ_BIT(DIVx->SR, DIV_SR_DIVBYZERO_Msk) == (DIV_SR_DIVBYZERO_Msk));
}

/**
  * @brief    Get Busy flag
  * @rmtoll   SR    BUSY    FL_DIV_IsActiveFlag_Busy
  * @param    DIVx DIV instance
  * @retval   State of bit (1 or 0).
  */
__STATIC_INLINE uint32_t FL_DIV_IsActiveFlag_Busy(DIV_Type *DIVx)
{
    return (uint32_t)(READ_BIT(DIVx->SR, DIV_SR_BUSY_Msk) == (DIV_SR_BUSY_Msk));
}

/**
  * @}
  */

/** @defgroup DIVAS_FL_EF_Init Initialization and de-initialization functions
  * @{
  */

FL_ErrorStatus FL_DIVAS_DeInit(DIV_Type *DIVx);
FL_ErrorStatus FL_DIVAS_Init(DIV_Type *DIVx);

/**
  * @}
  */

/** @defgroup DIVAS_FL_EF_Operation Opeartion functions
  * @{
  */

uint32_t FL_DIVAS_Hdiv_Calculation(DIV_Type *DIVx, int32_t DivisorEnd, int16_t Divisor, int32_t *Quotient, int16_t *Residue);

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __FM33LE0XXA_FL_DIVAS_H*/

/*************************Py_Code_Generator Version: 0.1-0.11-0.2 @ 2020-09-23*************************/
/********************** (C) COPYRIGHT Fudan Microelectronics **** END OF FILE ***********************/
